package com.megoc.menu.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.megoc.menu.R;
import com.megoc.menu.model.BaseTag;

import java.util.List;

/**
 * Created by Nong on 2015/10/13.
 */
public class MenuGridViewAdapter extends BaseAdapter{
    private List<BaseTag> tags;
    private Context context;

    public MenuGridViewAdapter(List<BaseTag> tags, Context context) {
        this.tags = tags;
        this.context = context;
    }

    @Override
    public int getCount() {
        return tags.size();
    }

    @Override
    public Object getItem(int i) {
        return tags.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        if (view==null){
            viewHolder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.item_menu_person_gridview,null);
            viewHolder.simpleDraweeView= (SimpleDraweeView) view.findViewById(R.id.person_gridview_img);
            viewHolder.textView= (TextView) view.findViewById(R.id.person_gridview_text);
            view.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) view.getTag();
        }
        BaseTag tag=tags.get(i);
        Uri uri=Uri.parse(tag.getImg());
        viewHolder.simpleDraweeView.setImageURI(uri);
        viewHolder.textView.setText(tag.getTitle());
        return view;
    }
    class ViewHolder{
        SimpleDraweeView simpleDraweeView;
        TextView textView;
    }
}
